package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.*;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.example.EmpInfoExample.*;

/**
 * 员工信息
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpBySiteQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_USER_ID, example = E_USER_ID)
    @Length(max = 32)
    private String userId;

    @ApiParam(value = N_NUMBER, example = E_NUMBER)
    @Length(max = 32)
    private String number;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 50)
    private String name;

    @ApiParam(value = "员工状态" )
    private Integer status;

    @ApiParam(value = N_CONTRACT_SUBJECT, example = E_CONTRACT_SUBJECT)
    @Length(max = 32)
    private String contractSubject;

    /**
     * 性别
     */
    @ApiParam(value = N_GENDER, example = E_GENDER, allowableValues = GenderEnum.VALUES_STR)
    private Integer gender;

    /**
     * 合同状态
     */
    @ApiParam(value = "合同状态")
    private Integer contractsStatus;

    /**
     * 岗位类型
     */
    @ApiParam(value = "岗位类型", example = E_POST_TYPE, allowableValues = PostType.VALUES_STR)
    private Integer postType;

    /**
     * 学历
     */
    @ApiParam(value = N_HIGHEST_EDUCATION, example = E_HIGHEST_EDUCATION)
    @Length(max = 50)
    private String highestEducation;

    /**
     * 公司Id
     */
    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    /**
     * 公司Ids
     */
    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    private String companyIds;
    /**
     * 员工类型
     */
    @ApiParam(value = N_EMPLOY_TYPE, example = E_EMPLOY_TYPE)
    private Boolean employType;

    /**
     * 工作性质
     */
    @ApiParam(value = N_INFORMAL_TYPE, example = E_INFORMAL_TYPE)
    private Integer informalType;

    /**
     * 工作性质
     */
    @ApiParam(value = N_FORMAL_TYPE, example = E_FORMAL_TYPE)
    private Integer formalType;

    /**
     * 信息补充
     */

    @ApiParam(value = N_IS_IMPROVE, example = E_IS_IMPROVE)
    private Boolean isImprove;

    /**
     * 实名认证
     */
    @ApiParam(value = N_VERIFIED, example = E_VERIFIED, allowableValues = VerifiedEnum.VALUES_STR)
    private Boolean verified;

    /**
     * 婚姻状况
     */
    @ApiParam(value = N_MARITAL_STATUS, example = E_MARITAL_STATUS, allowableValues = EmpMaritalStatus.VALUES_STR)
    private Integer maritalStatus;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 政治面貌
     */
    @ApiParam(value = N_POLITICAL_STATUS, example = E_POLITICAL_STATUS, allowableValues = EmpPoliticalStatus.VALUES_STR)
    private Integer politicalStatus;
    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpBySiteQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

    @ApiParam(value = "员工工作城市code集合")
    private List<String> joinCityCodeList;

    @ApiParam(value = "员工所属公司id集合")
    private List<String> companyIdList;

    @ApiParam(value = "员工id集合")
    private List<String> empIdList;


    /**
     * 姓名或手机号
     */
    @ApiParam(value = N_NAME_OR_PHONE, example = E_NAME_OR_PHONE)
    @Length(max = 255)
    private String nameOrPhone;

    @ApiParam(value = "姓名或手机号或邮箱", example = "1")
    private String nameOrPhoneOrEmail;

    /**
     * 部门ID
     */
    @ApiParam(value = N_DEP_ID, example = E_DEP_ID)
    @Length(max = 32)
    private String depId;

    /**
     * 岗位ID
     */
    @ApiParam(value = N_POSITION_ID, example = E_POSITION_ID)
    @Length(max = 32)
    private String positionId;


    /**
     * 调岗时间查询范围
     */
    @ApiParam(value = "调岗开始时间", example = E_LEAVE_DATE_START)
    private Date transferDateStart;

    @ApiParam(value = "调岗截止时间", example = E_LEAVE_DATE_END)
    private Date transferDateEnd;

    @ApiParam(value = "是否展示子公司的员工,默认不展示")
    private Boolean showChildCompanyDep = false;

    @ApiParam(value = "员工的id，用来位置查询")
    private String empId;

    @ApiParam(value = "渠道id")
    private String channelId;

    @ApiParam(value = "标签（支持多个，用逗号隔开）")
    private String tags;

    @ApiParam(value = "标签List")
    private List<String> tagList;

    /**
     * 入职时间查询范围
     */
    @ApiParam(value = N_JOIN_DATE_START, example = E_JOIN_DATE_START)
    private Date joinDateStart;
    @ApiParam(value = N_JOIN_DATE_END, example = E_JOIN_DATE_END)
    private Date joinDateEnd;


}

